package cn.edu.jxau.core.controller;

import cn.edu.jxau.core.util.StringUtil;
import org.apache.log4j.PropertyConfigurator;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

/**
 * 配置全局项目根路径
 * MangoDai
 * 2017 09 13 6:54 PM
 */
public class ConfigServlet extends HttpServlet {
    protected static String webRealPath = null;

    /**
     * 初始化项目，配置Log4j的文件路径
     * @param config
     * @throws ServletException
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        String root = config.getServletContext().getRealPath("/");
        webRealPath = root;
        String log4jLocation = config.getInitParameter("log4jLocation");
        System.setProperty("webRoot", root);
        if (!StringUtil.isEmpty(log4jLocation)) {
            PropertyConfigurator.configure(root + log4jLocation);
        }
    }
}
